const PREFIX = import.meta.env.VITE_LOCAL_STORAGE_KEY_PREFIX


/**
 * 获取item
 * @param {*} key  
 * @param {*}  
 * @returns 
 */
export const Get = (key) => {
    let StrValue = localStorage.getItem(PREFIX + key)
    try {
        StrValue = JSON.parse(StrValue)
        let {value} = StrValue
        return value
    } catch (e) {
        StrValue = null
        return StrValue
    }

}
export const Set = (key, value) => {
    let inset = {
        key: key,
        value: value
    }
    return localStorage.setItem(PREFIX + key, JSON.stringify(inset))
}
export const Remove = (key) => {
    return localStorage.removeItem(PREFIX + key)
}
export const Clear = () => {
    return localStorage.clear()
}
export const Has = (key) => {
    return localStorage.getItem(PREFIX + key) !== null
}
export const Keys = () => {
    let keys = []
    for (let i = 0; i < localStorage.length; i++) {
        keys.push(localStorage.key(i))
    }
    return keys
}

export const Size = () => {
    return localStorage.length
}
export default {
    Get,
    Set,
    Remove,
    Clear,
    Has,
    Keys,
    Size
}